import pytest # type: ignore
from pathlib import Path
import json
import tempfile
import shutil

@pytest.fixture
def temp_dir():
    """创建临时目录"""
    with tempfile.TemporaryDirectory() as tmpdirname:
        yield Path(tmpdirname)

@pytest.fixture
def sample_word_bank():
    """示例词库数据"""
    return {
        'primary': ['apple', 'book', 'cat'],
        'nce1': ['excuse', 'ticket', 'train'],
        'custom': ['test1', 'test2', 'test3']
    }

@pytest.fixture
def sample_stats():
    """示例统计数据"""
    return {
        'levels': {
            'primary': {
                'correct': 10,
                'wrong': 2,
                'total_time': 60,
                'best_wpm': 15
            }
        },
        'total_practice_time': 60,
        'last_practice': '2024-01-01T12:00:00',
        'history': []
    }

@pytest.fixture
def temp_word_bank_file(temp_dir):
    """创建临时词库文件"""
    file_path = temp_dir / 'test_words.txt'
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write('word1\nword2\nword3\n')
    return file_path

@pytest.fixture
def temp_stats_file(temp_dir, sample_stats):
    """创建临时统计文件"""
    file_path = temp_dir / 'statistics.json'
    with open(file_path, 'w', encoding='utf-8') as f:
        json.dump(sample_stats, f)
    return file_path
